import pymysql
db = pymysql.connect(host="localhost", user="root", password="12345678", database="mrsoft", charset="utf8")

cursor = db.cursor()


try:
    cursor.execute('DELETE FROM books WHERE category = %s', ('PHP',))
    cursor.execute('SELECT * FROM books')
    result = cursor.fetchall()
    for item in result:
      print('图书：《', item[1], '》， 价格：￥',item[3], '元')
    db.commit()
except ValueError as e:
    print(e)
    db.rollback()